﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ProjetCom.Ctrl;
using ProjetCom.Model.Snake;

namespace ProjetCom.Vue
{
    class LevelSnake : Level
    {
        // Texture
        private Dictionary<string, Texture2D> m_BlockSheets;

        public LevelSnake(IServiceProvider p_serviceProvider, CtrlSnake p_ctrl)
            : base(p_serviceProvider, p_ctrl)
        {
            // load the textures
            m_BlockSheets = new Dictionary<string, Texture2D>();
            m_BlockSheets.Add("Snake", Content.Load<Texture2D>("Sprites/Snake/snake"));
            m_BlockSheets.Add("Obstacle", Content.Load<Texture2D>("Sprites/Snake/obstacle"));


            ColorBackground = new Color(164, 199, 141);
        }

      
        /// <summary>
        /// Dessine
        /// </summary>
        /// <param name="_gameTime"></param>
        /// <param name="p_spriteBatch"></param>
        override public void Draw(SpriteBatch p_spriteBatch)
        {
            // Le score devant, puis le snake et enfin les blocks
            DrawObstacle(p_spriteBatch);
            DrawSnake(p_spriteBatch);
            DrawScore(p_spriteBatch);
        }

        /// <summary>
        ///  Dessine le snake
        /// </summary>
        /// <param name="p_spriteBatch"></param>
        private void DrawSnake(SpriteBatch p_spriteBatch)
        {
            foreach (BlockSnake block in ((CtrlSnake) m_Ctrl).ListeBlock)
            {
                Rectangle sourceSnake = new Rectangle(block.X * BlockSnake.Width, block.Y * BlockSnake.Height, BlockSnake.Width, BlockSnake.Height);
                p_spriteBatch.Draw(m_BlockSheets["Snake"], sourceSnake, Color.White);
            }
        }

        /// <summary>
        /// Dessine l'obstacle
        /// </summary>
        /// <param name="p_spriteBatch"></param>
        private void DrawObstacle(SpriteBatch p_spriteBatch)
        {
            Rectangle sourceObstacle = new Rectangle(((CtrlSnake) m_Ctrl).Obstacle.X * BlockSnake.Width, ((CtrlSnake) m_Ctrl).Obstacle.Y * BlockSnake.Height, BlockSnake.Width, BlockSnake.Height);
            p_spriteBatch.Draw(m_BlockSheets["Obstacle"], sourceObstacle, Color.White);
        }

        public override void Dispose()
        {
        }
    }
}
